package network.client;


import java.io.IOException;
import java.net.InetAddress;

import messages.BaseMessage;
import messages.MessageType;
import messages.registration.PersonDispatcherRegistrationMessage;

import observer.ObserverThread;
import system.GlobalData;
import system.PersonDispatcherMain;

public class PersonDispatcherElevatorThread extends ObserverThread {

    public PersonDispatcherElevatorThread(InetAddress remoteAddr, int remotePort)
    {
        super(remoteAddr, remotePort);
    }
    
    @Override
    public void run()
    {
        super.run();
        
        PersonDispatcherMain.initStatus(false);
    }
    
    @Override
    public boolean onStart()
    {
        
        try
        {
            GlobalData.loadGroupDispatcherState(getRemoteSocket());
        }
        catch (IOException e)
        {
            e.printStackTrace();
            
            PersonDispatcherMain.initStatus(false);
            
            return false;
        }
        
        PersonDispatcherMain.initStatus(true);
        
        return true;
        
    }
    
    @Override
    public BaseMessage getRegistrationMessage()
    {
        return new PersonDispatcherRegistrationMessage(GlobalData.LISTEN_PORT);
    }
    
    @Override
    protected boolean isProperRegistrationAck(MessageType type)
    {
        return type == MessageType.PersonDispatcherRegistrationMessage;
    }

}
